/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package shareit;

/**
 *
 * @author steve
 */
import java.sql.*;

public class DB {

public static void main(String[] args)
{
		//try block for sql exceptions
	try
	{
			//create driver - ALTER TO SUIT YOUR DRIVER/ DBMS
		Class.forName("com.mysql.jdbc.Driver").newInstance();

			//database connection code - ENTER YOUR DETAILS
		String username = "seng330";
		String password = "fightingchickensco";

			//URL - ALTER TO CONNECT TO YOUR DATABASE
		String dbURL = "jdbc:mysql://sql09.freemysql.net/seng330project?user="
			+ username + "&password=" + password;

			//create the connection - ALTER FOR YOUR DBMS
		java.sql.Connection myConnection =
			DriverManager.getConnection(dbURL);

			//create statement handle for executing queries
		Statement stat = myConnection.createStatement();

		//query to select all of the data from a table
		String selectQuery = "Select * from VehicleDB";
			//get the results
		ResultSet results = stat.executeQuery(selectQuery);
		//output the results
		while (results.next())
		{
			//example - column is called 'firstname'
		System.out.println("Vehicle ID: " +
			results.getString("vehicleId"));
		}


	}
	catch( Exception E )
	{ System.out.println( E.getMessage());
}
}
}
